// models/Course.js
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
const Video = require('./Video')

const Course = sequelize.define('Course', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  title: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  description: {
    type: DataTypes.STRING,
  },
  price: {
    type: DataTypes.FLOAT,
    allowNull: false,
  },
  status: {
    type: DataTypes.ENUM('published', 'unpublished'),
    allowNull: false,
    defaultValue: 'unpublished',
  },
  displayImage: {
    type: DataTypes.STRING, // 存储展示图片的路径
  },
  detailImages: {
    type: DataTypes.JSON, // 存储详细图片路径的数组
  },
});

Course.hasMany(Video, { foreignKey: 'courseId' }); // 假设 Video 模型有一个名为 courseId 的外键

module.exports = Course;
